<?php
class categorias extends controller
{
	private $t = null;
	public function __construct(tpl & $plantilla)
	{
		$plantilla->set('title','Categorias de receta');
		$this->t = & $plantilla;
	}
	public function categorias()
	{
		$this->t->parse('categorias');
		//$categorias = DB::select('recetas',('*') );
		$categorias = DB::sql(<<<SQL
		SELECT 
			cat.*,
			COUNT(r.id) AS total 
		FROM recetas AS cat
			LEFT JOIN recetas_descripcion AS r ON r.recetas_id=cat.recetas_id
		GROUP BY cat.recetas_id
SQL
);
		if($categorias->execute())
		{
			$this->t->assign('categorias', $categorias->fetchAll(DB::FETCH_ASSOC));
			$this->t->assign('url', BASE_URL_FULL . '/admin/recetas.php/listar:recetas/');
		}
		return $this->t->render('categorias');
	}
	public function verdurasJSON()
	{
		$verduras = DB::select('verduras',
			array('verduraid AS id',
			'nombre','tmb','fot','minerales','vitaminas','proteinas','calorias',
			'prop','linkC','riesgos','linkD'));
		$verduras->execute();
		echo json_encode( $verduras->fetchAll(DB::FETCH_ASSOC));
		die();
	}
	public function getDefault()
	{
		return $this->categorias();
		return "<h1>categoria por defecto</h1>";
	}
}